#include <vector>
#include <iostream>
#include <set>
#include <unordered_set>
#include <algorithm>

using namespace std;

class Solution 
{
public:
    int longestConsecutive(vector<int>& nums) 
    {
        if(nums.empty())
        {
            return 0;
        }
        unordered_set<int> us(nums.begin(), nums.end());
        int maxCount = 1;
        for(auto it = us.begin(); it != us.end(); it++)
        {
            if(us.find(*it - 1) != us.end())
            {
                continue;
            }
            int count = 1;
            int currentNum = *it;
            while (us.find(currentNum + 1) != us.end())
            {
                count++;
                maxCount = max(count, maxCount);
                currentNum++;
            }
        }
        return maxCount;
    }
};

int main() 
{
    Solution solution;
    
    // 测试案例1: [100,4,200,1,3,2]
    cout << "测试案例1:" << endl;
    vector<int> nums1 = {100, 4, 200, 1, 3, 2};
    cout << "输入: [100,4,200,1,3,2]" << endl;
    int result1 = solution.longestConsecutive(nums1);
    cout << "输出: " << result1 << endl;
    cout << "期望: 4 (连续序列 [1,2,3,4])" << endl << endl;
    
    // 测试案例2: [0,3,7,2,5,8,4,6,0,1]
    cout << "测试案例2:" << endl;
    vector<int> nums2 = {0, 3, 7, 2, 5, 8, 4, 6, 0, 1};
    cout << "输入: [0,3,7,2,5,8,4,6,0,1]" << endl;
    int result2 = solution.longestConsecutive(nums2);
    cout << "输出: " << result2 << endl;
    cout << "期望: 9 (连续序列 [0,1,2,3,4,5,6,7,8])" << endl << endl;
    
    // 测试案例3: [1,0,1,2]
    cout << "测试案例3:" << endl;
    vector<int> nums3 = {1, 0, 1, 2};
    cout << "输入: [1,0,1,2]" << endl;
    int result3 = solution.longestConsecutive(nums3);
    cout << "输出: " << result3 << endl;
    cout << "期望: 3 (连续序列 [0,1,2])" << endl << endl;
    
    // 测试案例4: 空数组
    cout << "测试案例4 (空数组):" << endl;
    vector<int> nums4 = {};
    cout << "输入: []" << endl;
    int result4 = solution.longestConsecutive(nums4);
    cout << "输出: " << result4 << endl;
    cout << "期望: 0" << endl << endl;
    
    // 测试案例5: 单个元素
    cout << "测试案例5 (单个元素):" << endl;
    vector<int> nums5 = {1};
    cout << "输入: [1]" << endl;
    int result5 = solution.longestConsecutive(nums5);
    cout << "输出: " << result5 << endl;
    cout << "期望: 1" << endl << endl;
    
    // 测试案例6: 负数序列
    cout << "测试案例6 (负数序列):" << endl;
    vector<int> nums6 = {-1, -2, -3, 0, 1, 2, 3};
    cout << "输入: [-1,-2,-3,0,1,2,3]" << endl;
    int result6 = solution.longestConsecutive(nums6);
    cout << "输出: " << result6 << endl;
    cout << "期望: 7 (连续序列 [-3,-2,-1,0,1,2,3])" << endl << endl;
    
    // 测试案例7: 无连续序列
    cout << "测试案例7 (无连续序列):" << endl;
    vector<int> nums7 = {1, 3, 5, 7, 9};
    cout << "输入: [1,3,5,7,9]" << endl;
    int result7 = solution.longestConsecutive(nums7);
    cout << "输出: " << result7 << endl;
    cout << "期望: 1" << endl << endl;
    
    // 测试案例8: 重复元素
    cout << "测试案例8 (重复元素):" << endl;
    vector<int> nums8 = {1, 2, 2, 3, 4, 4, 5};
    cout << "输入: [1,2,2,3,4,4,5]" << endl;
    int result8 = solution.longestConsecutive(nums8);
    cout << "输出: " << result8 << endl;
    cout << "期望: 5 (连续序列 [1,2,3,4,5])" << endl << endl;
    
    return 0;
}